import axios from 'axios'
import nProgress from 'nprogress'
import 'nprogress/nprogress.css'

const request = axios.create({
    baseURL:process.env.VUE_APP_MOCKAPI,
    timeout:10000
})

request.interceptors.request.use((config) => {
    nProgress.start()
    return config
},(error) => {
    nProgress.done()
    return Promise.reject(error)
})

request.interceptors.response.use((response) => {
    nProgress.done()
    if(response.data.code === 200){
        return response.data.data
    }else{
        return Promise.reject({message:response.data.message})
    }
},(error) => {
    nProgress.done()
    return Promise.reject(error)
})

export default request